

#封装面包屑组件
from apps.goods.models import GoodsCategory


def get_breadcrumb(category_id):
    #获取cat3
    cat3 = GoodsCategory.objects.get(id = category_id)
    #获取cat2
    cat2 = cat3.parent
    #获取cat1
    cat1 = cat2.parent

    breadcrumb = {
        'cat1':{
            'id':cat1.id,
            'name':cat1.name,
            # 'url':cat1.goodschannel_set.get(category = cat1).url
            'url': cat1.goodschannel_set.all()[0].url
        },
        'cat2':cat2,
        'cat3':cat3
    }

    return breadcrumb
